<template>
  <div >
    <!-- 小区搜索列表 -->
<form action="/">
  <van-search
    v-model="value"
    placeholder="请输入小区或地址"
    @search="onSearch"
    @cancel="onCancel"
  />
</form>

<!-- 列表 -->
<van-list>
  <van-cell v-for="(item,index) in list" :key="index" :title="item.communityName" @click="clickXq(item)"/>
</van-list>
  </div>
</template>

<script>

import { xqName } from '@/api/user'
import { getcityValue } from '@/utils/storage'
export default {
  data () {
    return {
      value: '',
      cityValue: '',
      list: []
    }
  },
  methods: {
    clickXq (item) {
      localStorage.setItem('community', item.community)
      localStorage.setItem('communityName', item.communityName)
      this.$router.go(-1)
    },
    /* 文档 搜索确定时发送请求数据 */
    async onSearch (val) {
      this.cityValue = getcityValue()
      console.log(this.cityValue)
      console.log(val)
      const res = await xqName({
        name: val, /* 输入框的值 */
        id: this.cityValue/* 本地获取到的id */
      })// xqName()调用
      console.log(res)
      this.list = res.body
    },
    onCancel () {
      this.$router.push('/gotorent')
    },
    onLoad () {

    }
  }

}

</script>

<style>

</style>
